package cn.hackcloud.concurrency.activeobjects;

/**
 * ActiveDaemonThread是一个守护线程，主要是从queue中获取Message然后执行
 * execute方法(注意:保持为线程命名的习惯是一个比较好的编程习惯)。
 */
public class ActiveDaemonThread extends Thread {
    private final ActiveMessageQueue queue;

    public ActiveDaemonThread(ActiveMessageQueue queue) {
        super("ActiveDaemonThread");
        this.queue = queue;
        setDaemon(true);
    }

    @Override
    public void run() {
        for (; ; ) {
            ActiveMessage methodMessage = this.queue.take();
            methodMessage.execute();
        }
    }
}
